package hashTable;


import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;


public class HashPicture {
	BufferedImage hashState;

	int[] hTable;
	public HashPicture(IHashTable hashTable) {
		hTable = hashTable.getTable();
		hashState = new BufferedImage(hashTable.getTable().length, 20, BufferedImage.TYPE_INT_RGB);

		
		int color = 0xFFFFFFFF;
		for (int j = 0; j < hashState.getWidth(); j++)
		for (int i = 0; i < hashState.getHeight();i++) {
			hashState.setRGB(j, i, color);
		}
		
		

	}
	
	public ImageIcon getImageIcon(){
		
		for(int i = 0; i < hTable.length; i++) {
			if (hTable[i] != 0) for (int j = 0; j < 20; j++) hashState.setRGB(i, j, 0xFF000000);
		}
		
		return new ImageIcon(hashState);
	}
	
	public int getClusterNumber() {
		int count = 0;
		boolean inCluster = false;
		
		for (int i = 0; i < hTable.length; i++) {
			if (inCluster == false && hTable[i] != 0) {
				count++;
				inCluster = true;
			}
			if (inCluster == true && hTable[i] == 0) inCluster = false;
		}
		
		return count;
	}
}
